package com.sheepone.util;

import com.hummeling.if97.IF97;
import com.sheepone.util.enums.PressureUnit;

/**
 * @author Miss.杨
 * @description 内部实用if97工具包实现对应于matlab的XSteam函数
 * @file doc/if97/if97的XSteam函数实用说明.png
 * @since 2024/2/6 - 19:07
 */
public class XSteamUtil {

    private static final IF97 if97 = new IF97(IF97.UnitSystem.ENGINEERING);

    public static double h_pt(double pressure, double temperature) {
        if (pressure > 0) {
            return if97.specificEnthalpyPT(pressure, temperature);
        }
        return 0;
    }

    public static double h_pt(double pressure, double temperature, PressureUnit pressureUnit) {
        if (pressure > 0) {
            return if97.specificEnthalpyPT(pressureUnit.convert(pressure, PressureUnit.BAR), temperature);
        }
        return 0;
    }

    /**
     * 默认压力单位为Bar
     *
     * @param pressure
     * @return
     */
    public static double Tsat_p(double pressure) {
        if (pressure > 0) {
            return if97.saturationTemperatureP(pressure);
        }
        return 0;
    }

    public static double Tsat_p(double pressure, PressureUnit pressureUnit) {
        if (pressure > 0) {
            return if97.saturationTemperatureP(pressureUnit.convert(pressure, PressureUnit.BAR));
        }
        return 0;
    }
}